<template>
	<view>
		<van-empty description="暂无扫码内容" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				taskId: null,
				id: null,
				item: null
			}
		},
		onLoad(options) {
			this.item = JSON.parse(options.item)
			this.id = +JSON.parse(options.item).巡逻点id
			this.taskId = +options.taskId
			this.scanPatrol()
		},
		methods: {
			scanPatrol() {
				let msg = null
				// 只允许通过相机扫码
				uni.scanCode({
					onlyFromCamera: true,
					success: (res) => {
						console.log(res)
						if (res.scanType == 'QR_CODE') {
							try {
								// console.log(JSON.parse(res.result))
								// console.log(index)
								let obj = JSON.parse(res.result.trim())
								console.log('条码内容：', obj);
								if(this.id !== obj.id) {
									msg = '当前二维码与该巡逻点不匹配'
									uni.showModal({
										title: '提示',
										content: msg,
										showCancel: false,
										success: function(res) {
											uni.navigateBack({
												delta: -1
											})
										},
									})
									return
								}
								if (obj.qrcode == 'patrolTask') {
									
									if (obj.type == "patrolPointCode") {
										if(obj['定位检查']) {
											uni.redirectTo({
												url: "/taskSystem/checkLocation/checkLocation?item=" + JSON.stringify(this.item)
											})
										}else {
											uni.redirectTo({
												url: "/taskSystem/completePatrol/completePatrol?id=" + this.item.id + '&taskId=' + this.taskId
											})
										}
			
									}
			
								} else {
									msg = "非法二维码"
								}
							} catch (e) {
								console.log(e)
								msg = "非法二维码"
							}
			
						} else {
							msg = "请扫描二维码"
						}
						if (msg) {
							uni.showModal({
								title: '提示',
								content: msg,
								showCancel: false,
								success: function(res) {
			
									uni.switchTab({
										url: "../index/index"
									})
								},
							})
			
						}
			
						// console.log('条码类型：' + res.scanType);
						// console.log('条码内容：' + res.result);
					},
					fail: function(err) {
						console.log('err',err)
						// uni.showModal({
						//     title: '提示',
						//     content: '请扫描正确的二维码',
						// 	showCancel: false,
						//     success: function (res) {
						//         if (res.confirm) {
						//             console.log('用户点击确定');
						//         } else if (res.cancel) {
						//             console.log('用户点击取消');
						//         }
						//     }
						// });
					}
				});
			}
		}
	}
</script>

<style lang="scss">
.van-empty {
	margin-top: 200rpx;
}
</style>
